 <#include "../../layout/mainLayout.ftl">

<@layout>
    <div class="layui-card">
        <div class="layui-card-header">
            <span class="layui-breadcrumb">
                ${breadcrumb!''}
            </span>
        </div>
    </div>

    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" id="queryForm">
                <div class="layui-form-item">
                	<label class="layui-form-label" style="width: auto">审核状态</label>
                    <div class="layui-input-inline">
                        <select name="result">
					           <option value="1" checked>未审核</option>
					           <option value="2">已审核</option>
                        </select>
                    </div>
                    <div>
	                    <button type="button" class="layui-btn" lay-submit="" id="queryPage">查询</button>
					</div>
    			</div>
              </div>
            </form>
            <table id="dataTable" lay-filter="dataTable"></table>
        </div>
    </div>

</@layout>
<@js>
    <script>
        layui.use(['laydate', 'table', 'layer', 'global'], function () {
            var table = layui.table, layer = layui.layer, $ = layui.$, laydate = layui.laydate;
            //起始时间插件
            laydate.render({
                elem: '#createTime',
                type: 'date'
            });
            //结束时间插件
            laydate.render({
                elem: '#createTimeRange',
                type: 'date',
                //range: true
            });

            var dataTable = table.render({
                elem: '#dataTable',
                url: '/tMatter/approvalPageData?state=1', //数据接口
                where: {},
                page: true, //开启分页
                done: function(){
                	var resultType = ''
                	$.each($('#queryForm').serializeArray(), function (i, field) {
                		if(field.name == 'result') resultType = field.value
                    });
                	if(resultType == '2'){
                		$('.auditing').hide();
                	}
                },
                cols: [[ //表头
                    {type: 'checkbox'},
                    {field: 'matterName', title: '事项名称', align: 'center'},
                    {field: 'powerMatterCode', title: '主项编码', align: 'center'},
                    {field: 'matterAttr', title: '事项属性', align: 'center', templet: function(d){
                    	if(d.matterAttr == 1){
                    		return '公共服务'
                    	} if(d.matterAttr == 2){
                    		return '权力事项'
                    	}
                      }
                    },
                    {field: 'matterType', title: '事项类型', align: 'center'},
                    {field: 'createDate', title: '创建时间', align: 'center'},
                    {field: 'approvalState', title: '审核状态', align: 'center', templet: function(d){
                    	if(d.approvalState == 0){
                    		return '未送审'
                    	} if(d.approvalState == 1){
                    		return '主管部门审核中'
                    	} if(d.approvalState == 2){
                    		return '法制办审核中'
                    	} if(d.approvalState == 3){
                    		return '审管办审核中'
                    	} if(d.approvalState == 4){
                    		return '财政局审核中'
                    	} if(d.approvalState == 5){
                    		return '编委办审核中'
                    	} if(d.approvalState == 6){
                    		return '数据资源局审核中'
                    	} if(d.approvalState == 7){
                    		return '审核通过'
                    	} if(d.approvalState == 8){
                    		return '已驳回'
                    	}
                      }
                    },
                    {
                        title: '操作', toolbar: '<div>' +
                            '<a class="layui-btn layui-btn-xs layui-btn-primary auditing" lay-event="auditing">审核</a>' +
                            '<a class="layui-btn layui-btn-xs layui-btn-primary look" lay-event="look">查看</a>' +
                            '</div>',
                        minWidth: 240
                    }
                ]]
            });

            //触发高级检索
            $(function(){
		       $('.btn').click(function(){
		           $('.content').toggle();
		      	 })
		    })

            window.reloadTable = function (reset = false) {
                var fields = {};
                $.each($('#queryForm').serializeArray(), function (i, field) {
                    fields[field.name] = field.value;
                });
                dataTable.reload({
                    where: fields,
                    page: reset?{
                        curr: 1 //重新从第 1 页开始
                    }:undefined
                });
            };

            table.on('tool(dataTable)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                if (layEvent === 'auditing') { //审批
                    $.ajax({
                        url: '/tMatter/approvalDetail',
                        data: {id: data.id},
                        async: false,
                        success: function (data, status, xhr) {
                            layer.open({
                                type: 1,
                                title: '审核',
                                area: ['600px', '400px'],
                                content: data,
                                move:false
                            });
                        }
                    });
                } else if (layEvent === 'look') { //查询 
                    window.open('/tMatter/approvalDetailLook?id='+data.id,'_self')
                }
            });

            $('#queryPage').click(function () {
                reloadTable(true);
            });
        });
    </script>
</@js>